package com.yixq.soa.service.web.utils;

import java.lang.reflect.Method;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.servlet.mvc.condition.RequestCondition;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import com.yixq.soa.service.web.annotation.Ver;



public class DoorduRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
	@Override
	protected RequestCondition<ApiVesrsionCondition> getCustomTypeCondition(Class<?> handlerType) {
		Ver apiVersion = AnnotationUtils.findAnnotation(handlerType, Ver.class);
		return createCondition(apiVersion);
	}

	@Override
	protected RequestCondition<ApiVesrsionCondition> getCustomMethodCondition(Method method) {
		Ver apiVersion = AnnotationUtils.findAnnotation(method, Ver.class);
		return createCondition(apiVersion);
	}

	private RequestCondition<ApiVesrsionCondition> createCondition(Ver apiVersion) {
		return apiVersion == null ? null : new ApiVesrsionCondition(apiVersion.value());
	}
}
